#
# missile.py -- missile object
# 
# author: Tom "Knio" Flanagan
#         knio@h4xn3t.net
#         theknio@gmail.com
#         irc.freenode.net - Knio - #python #pygame #py
#
# this file released under Public Domain
#

from constants import *
import object

class Missile(object.Object):
    def move(self):
        self.a = self.maxa
        self.life -= 1
        if not self.life >= 0: return self.explode()
        if not self.target.state:
            self.t = 0.
            return object.Object.move(self)
        d = self.distance(self.target)
        if self.distance(self.target) <= self.range: self.explode()
        vec = self.target.coordinates(self.target.h,(d/self.s)*self.target.s*0.7)
        turn = self.direction(self.angle(vec))
        if     turn > self.maxt: self.t =  self.maxt
        elif  -turn > self.maxt: self.t = -self.maxt
        else: self.t = turn
        object.Object.move(self)

    def explode(self):
        self.currentsize = 0
        self.power = 1.0
        self.size *= 15
        self.view = None
        self.a = 0
        self.__class__ = explosion.Explosion
        
import explosion
